package com.coocaa.internship.controller;

import com.coocaa.internship.common.ResultData;
import com.coocaa.internship.pojo.PositionInfo;
import com.coocaa.internship.service.serviceImpl.PositionInfoServicelmpl;
import com.coocaa.internship.util.BindingResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

/**
 * @Description:
 * @Author: 凌贤
 * @Date: 2019-08-04
 * @Time: 18:44
 */
@RestController
@RequestMapping("/positionInfo")
public class PositionInfoController {
    @Autowired
    PositionInfoServicelmpl positionInfoServicelmpl;


    @RequestMapping(value = "/selectAll", method = RequestMethod.GET)
    public ResultData selectAll() {
        return positionInfoServicelmpl.selectAll();
    }

    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    public ResultData insert(PositionInfo positionInfo) {
        return positionInfoServicelmpl.insertPosition(positionInfo);
    }

    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    public ResultData delete(PositionInfo positionInfo) {
        return positionInfoServicelmpl.deletePosition(positionInfo);
    }

    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public ResultData update(PositionInfo positionInfo, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            BindingResultUtil.resolveErrors(bindingResult);
        }
        return positionInfoServicelmpl.updatePosition(positionInfo);
    }

    @RequestMapping(value = "/selectByCompanyId", method = RequestMethod.POST)
    public ResultData selectByCompanyId(PositionInfo positionInfo) {
        return positionInfoServicelmpl.selectByCompanyId(positionInfo.getCompanyId());
    }

    @RequestMapping(value = "/selectById", method = RequestMethod.GET)
    @ResponseBody
    public ResultData selectById(@RequestParam("positionId") Long positionId) {
        return positionInfoServicelmpl.selectPositionInfoById(positionId);
    }

}
